$(document).ready(function () {
	//时间格式化
	function dateFtt(fmt,date) {
		var o = {
			"M+" : date.getMonth()+1,                 //月份
			"d+" : date.getDate(),                    //日
			"h+" : date.getHours(),                   //小时
			"m+" : date.getMinutes(),                 //分
			"s+" : date.getSeconds(),                 //秒
			"q+" : Math.floor((date.getMonth()+3)/3), //季度
			"S"  : date.getMilliseconds()             //毫秒
		};
		if(/(y+)/.test(fmt))
			fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("("+ k +")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
		return fmt;
	}

	//获取地址栏参数
	function getUrlParms(name){
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if( r != null )
			return unescape(r[2]);
		return null;
	}

	//设置meal_info高度
	set_meal_info_height();
	function set_meal_info_height() {
		$('#meal_info').height( $(window).height() - $('.nav').outerHeight() ).css('overflow','auto');
	}

	//获取充值详情
	get_recharge_info();
	function get_recharge_info() {
		$.ajax({
			url: "/index/mealListDetail",
			type: "POST",
			dataType: "json",
			data: {
				order_id: getUrlParms('recharge_id')
			},
			success: function (data) {
				if( data.code == '1' ){
					fill_data_page(data.data);//填充数据到页面
				}else {

				}
			},
			error: function (err) {
				console.log(err);
			}
		})
	}

	//获取积分类型
	function get_score_type(type) {
		var score_type = '';//积分类型 1：普通  2：白金  3：钻石  5:黄金  6：口腔
		if( type == '1' ){
			score_type = '普通积分';
		}
		if( type == '2' ){
			score_type = '白金积分';
		}
		if( type == '3' ){
			score_type = '钻石积分';
		}
		if( type == '5' ){
			score_type = '黄金积分';
		}
		if( type == '6' ){
			score_type = '口腔积分';
		}
		return score_type;
	}

	//填充数据到页面
	function fill_data_page(data) {
		var html = '';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">订单号: <span>'+ data.order_id +'</span></div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">用户账号</div>';
		html += '<div class="pull-right">'+ data.user_mobile +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">用户姓名</div>';
		html += '<div class="pull-right">'+ data.user_name +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">套餐名称</div>';
		html += '<div class="pull-right">'+ data.project_name +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">套餐图片</div>';
		html += '<div class="pull-right"><img src="'+ data.cover_img +'" alt=""></div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">类型</div>';
		html += '<div class="pull-right active">'+ get_score_type(data.score_type) +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">消费人</div>';
		html += '<div class="pull-right">'+ data.consumer +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">消费人手机号</div>';
		html += '<div class="pull-right">'+ data.consumer_mobile +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">课室</div>';
		html += '<div class="pull-right">'+ data.class_room +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">服务商</div>';
		html += '<div class="pull-right">'+ data.servicer +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">咨询师</div>';
		html += '<div class="pull-right">'+ data.counselor +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">操作地点</div>';
		html += '<div class="pull-right">'+ data.operate_place +'</div>';
		html += '</div>';
		html += '<div class="clearfix">';
		html += '<div class="pull-left">消费时间</div>';
		html += '<div class="pull-right">' + dateFtt('yyyy-MM-dd',new Date(data.use_at*1000)) + '</div>';
		html += '</div>';

		$('#meal_info').html( html );
	}

	/* *****************************************************
	*                返回上一页
	* ******************************************************/
	go_back();
	function go_back() {
		$('#back').click(function () {
			history.go(-1);
		});
	}
});